#include <iostream>
#include <thread>
#include <mutex>
#include <fstream>

class LogFile
{
public:
    LogFile(){
        f.open("log.text");
    }
    void shared_print(std::string msg,int id)
    {
        std::lock_guard<std::mutex> locker(m_mutex);
        f<<"from"<<msg<<":"<<id<<std::endl;
    }
protected:
private:
    std::mutex m_mutex;
    std::ofstream f;
};


void function_2(LogFile &log)
{
    for(int i = 0; i > -100; --i)
    {
        log.shared_print("fn1:",i);
    }
}

int t2_main()
{
    LogFile log;
    std::thread t1(function_2,std::ref(log));

    for(int i=0; i < 100; ++i)
        log.shared_print("main:",i);

    t1.join();

    return 0;
}